<?
/*
 * Copyright 2004-2005 Sigve Indregard.
 *
 * This file is part of Laivsys.
 *
 * Laivsys is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Laivsys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Laivsys; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * $Id: pameldte.php 6 2005-07-11 23:14:47Z say $
 */
 
include("../db.php");
include("auth.php");
include("top.php");

if ($_REQUEST['process'] == 'true') {
	//this is a call from pameldtedetaljer.php
	$id=mysql_escape_string($_REQUEST['id']);
	if (! is_numeric($id)) {
		die ("ID er ikke en numerisk verdi!");
	}
	if ($_REQUEST['action'] == 'Innvilg')
		$sql="UPDATE deltakere SET Godkjent=1 WHERE ID=$id";
	elseif ($_REQUEST['action'] == 'Slett') {
		$sql="DELETE FROM dok_tilgang WHERE deltakerID=$id";
		mysql_query($sql);
		$sql="DELETE FROM deltakere WHERE ID=$id";
	} elseif ($_REQUEST['action'] == 'Endre passord') {
		$passord=mysql_escape_string($_REQUEST['passord']);
		$sql="UPDATE deltakere SET Passord=PASSWORD('$passord') WHERE ID=$id";
	} elseif ($_REQUEST['action'] == 'Avsl�')
		$sql="UPDATE deltakere SET Godkjent=-1 WHERE ID=$id";
	else
		$sql="UPDATE deltakere SET Godkjent=0 WHERE ID=$id";
	
	mysql_query($sql);

	if (mysql_errno())
		$info="Det oppstod en SQL-feil: ".mysql_error();
	else
		$info="Handlingen '".$_REQUEST['action']."' ble gjennomf�rt.";
	echo $info;
} 

$sql = "SELECT Navn, ID, DATE_FORMAT(Tstamp, '%Y-%m-%d %H:%i') AS tid FROM deltakere WHERE Godkjent=0 AND LaivID=$laivid ORDER BY Tstamp";
$limbos = mysql_query($sql);

$sql = "SELECT Navn, ID, DATE_FORMAT(Tstamp, '%Y-%m-%d %H:%i') AS tid FROM deltakere WHERE Godkjent=1 AND LaivID=$laivid ORDER BY Tstamp";
$coole = mysql_query($sql);

$sql = "SELECT Navn, ID, DATE_FORMAT(Tstamp, '%Y-%m-%d %H:%i') AS tid FROM deltakere WHERE Godkjent=-1 AND LaivID=$laivid ORDER BY Tstamp";
$teite = mysql_query($sql);

?>
<h1>P�meldtliste</h1>
<h2>Ikke behandlede p�meldinger (<?=mysql_num_rows($limbos)?>):</h2>
<?
if (mysql_num_rows($limbos)) {
	?>
	<table class="gridded">
	<?
	while ($deltaker=mysql_fetch_assoc($limbos)) {
		?>
		<tr>
		<td><?=$deltaker['Navn']?></td>
		<td><?=$deltaker['tid']?></td>
		<td><a href="pameldtedetaljer.php?id=<?=$deltaker['ID']?>">Detaljer...</a></td>
		</tr>
		<?
		}
	?>
	</table>
	<?
} else {
	?>
	<p><i>Ingen p�meldinger...</i>
	<?
}
?>
<h2>Godkjente p�meldinger (<?=mysql_num_rows($coole)?>):</h2>
<?
if (mysql_num_rows($coole)) {
	?>
	<table class="gridded">
	<?
	while ($deltaker=mysql_fetch_assoc($coole)) {
		?>
		<tr>
		<td><?=$deltaker['Navn']?></td>
		<td><?=$deltaker['Postnrsted']?></td>
		<td><a href="pameldtedetaljer.php?id=<?=$deltaker['ID']?>">Detaljer...</a></td>
		</tr>
		<?
		}
	?>
	</table>
	<?
} else {
	?>
	<p><i>Ingen p�meldinger...</i>
	<?
}
?>

<h2>Avviste p�meldinger (<?=mysql_num_rows($teite)?>):</h2>
<?
if (mysql_num_rows($teite)) {
	?>
	<table class="gridded">
	<?
	while ($deltaker=mysql_fetch_assoc($teite)) {
		?>
		<tr>
		<td><?=$deltaker['Navn']?></td>
		<td><?=$deltaker['Postnrsted']?></td>
		<td><a href="pameldtedetaljer.php?id=<?=$deltaker['ID']?>">Detaljer...</a></td>
		</tr>
		<?
		}
	?>
	</table>
	<?
} else {
	?>
	<p><i>Ingen p�meldinger...</i>
	<?
}

include("bottom.php");
?>
